home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / routing / mrouted.frm.z / mrouted.frm
Encoding:
Text File  |  2002-06-12  |  6.4 KB  |  252 lines

  1. #!/usr/bin/perl5
  2. #
  3. # mrouted.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: mrouted.frm,v 1.32 1998/02/11 23:20:17 jrw Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $conf = "/etc/mrouted.conf";
  26. $options = "/etc/config/mrouted.options";
  27. $dummy = "/etc/mrouted.conf.tmp";
  28. $data = "/etc/mrouted.conf.data";
  29. $myname = "mrouted.cgi";
  30. $help_page = "mrouted-help.html";
  31. $title = "Multicast Routing";
  32.  
  33. if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
  34. else { $br_index = 0; }
  35.  
  36. $js =
  37. "br_index = $br_index;
  38. $js_standard
  39. $js_error_box
  40. $js_help
  41. $js_ip
  42. function checkForm(form)  {
  43.     if (form.emr[br_index].checked && form.tun[br_index].checked) { // radio buttons are backwards
  44.         if (!testAddress(form.rip)) return (false);
  45.     }
  46.     return (true);
  47. }
  48. function testAddress(Ctrl) {
  49.     if (Ctrl.value == \"\") { 
  50.         errorBox (Ctrl, \"The remote IP address is required.\"); 
  51.         return (false); 
  52.     }
  53.     if (!testIPaddress(Ctrl.value,false)) { 
  54.         errorBox (Ctrl, \"The remote IP address \" + Ctrl.value 
  55.             + \" \\nis invalid.\"); 
  56.         return (false); 
  57.     }
  58.     return (true);
  59. }";
  60.  
  61. print "Content-type: text/html\n\n";
  62.  
  63. &get_fields;
  64.  
  65. &getInfo;
  66.  
  67. $help = $document_root . $ENV{"SCRIPT_NAME"};
  68. $help =~ s/cgi$/hlp/;
  69. exec $help if ($fld{'help'} eq "Help");
  70.  
  71. if ($fld{"doit"} eq "Ok") { 
  72.     if ($fld{'tun'} eq 'Yes' && $fld{'emr'} eq 'Yes') { &formValidation; }
  73.     &edit; 
  74.     &getInfo; 
  75. }
  76.  
  77. if (-e "/usr/etc/mrouted") { &generic; }
  78. else { 
  79.     &title_block($title);
  80.     &header_block($title);
  81.     print "<i>Multicast routing software not installed.  Install
  82.         subsystem </i><b>eoe.sw.ipgate</b><i> from the distribution CD.</i>";
  83. }
  84.  
  85. sub error {
  86.     &error_block($_[0]);
  87.     %val = %fld;
  88.     &generic;
  89.     exit 0;
  90. }
  91.  
  92. sub edit {
  93.     system("/etc/killall", "mrouted");
  94.     if ($fld{'emr'} eq 'Yes') {
  95.     if ($val{'emr'} eq 'No') { $message = "Multicast routing enabled.  "; }
  96.     if ($fld{'tun'} eq 'Yes') { 
  97.         &writeTunnel;
  98.         $message .= "Tunnel information updated.";
  99.     }
  100.     else { 
  101.         &turnOffTunnel;
  102.         $message .= "Tunnel disabled."; 
  103.     }
  104.     &restartDeamon("mrouted","/usr/etc/mrouted",$options);
  105.     system("/etc/chkconfig", "mrouted", "on");
  106.     } else { 
  107.     system("/etc/chkconfig", "mrouted", "off");
  108.     if ($val{'emr'} eq 'Yes') { 
  109.         $message = "Multicast routing disabled.";
  110.     } else { $message = "No change made."; }
  111.     $val{'emr'} = "No";
  112.     }
  113. }
  114.  
  115. sub turnOffTunnel {
  116.     ($dummy,$local) = split(/ /,$fld{'int'});
  117.  
  118.     open(IN,"< $conf");
  119.     open(OUT,"> $dummy");
  120.     while(<IN>) {
  121.     $line = $_;
  122.     @items = split(/\s+/,$line);
  123.     if ($items[0] eq "tunnel"  && $items[1] eq $local) { 
  124.         $line = "# $line"; 
  125.     }
  126.     print OUT $line;
  127.     }
  128.     close(IN);
  129.     close(OUT);
  130.     rename($dummy,$conf);
  131. }    
  132.  
  133. sub writeTunnel {
  134.     ($skip,$local) = split(/ /,$fld{'int'});
  135.  
  136.     open(IN,"< $conf");
  137.     open(OUT,"> $dummy");
  138.     $printed = 0;
  139.     while(<IN>) {
  140.     @items = split(/\s+/);
  141.     if ($items[0] ne "tunnel") { print OUT $_; }
  142.     else {
  143.         if ($items[1] eq $local) {
  144.         if ($items[2] eq $fld{'rip'}) {
  145.             print OUT $_;
  146.             $printed = 1;
  147.         } else {
  148.             print OUT "# $_";
  149.             print OUT "tunnel $local $fld{'rip'}\n";
  150.             $printed = 1;
  151.         }
  152.         } 
  153.     }
  154.     }
  155.     if (!$printed) { print OUT "tunnel $local $fld{'rip'}\n"; }
  156.     close(OUT);
  157.     close(IN);
  158.     rename($dummy,$conf);
  159. }
  160.  
  161. sub restartDeamon {
  162.     $command = "$_[1] ";
  163.     open(IN,"< $_[2]");
  164.     while(<IN>) { chop($_); $command .= " $_"; }
  165.     close(IN);
  166.     system($command);
  167. }
  168.  
  169. sub formValidation {
  170.     &error("Remote IP address required.") if $fld{'rip'} eq "";
  171.     if (&check_ipaddr($fld{'rip'})) {
  172.         &error("Invalid remote IP address");
  173.         &generic;
  174.         exit 0;
  175.     }
  176. }
  177.    
  178. sub generic {
  179.     &js_title_block($title,$js);
  180.     &header_block($title);
  181.  
  182.     print "<i>$message</i>";
  183.  
  184.     print qq|<form method=post name="StandardForm" action="$myname" onSubmit="return runSubmit()">|;
  185.  
  186.     print "<center><table cellpadding=5 width=450>";
  187.  
  188.     print "<tr><th align=left colspan=2>Enable multicast routing:</th>",
  189.       "<th align=left>", &radio('emr',$val{'emr'},"Yes","No"), 
  190.       "</th></tr><tr></tr>";
  191.  
  192.     print "<tr><th align=left colspan=2>Setup IP tunnel (if needed):</th>",
  193.       "<th><br></th></tr>";
  194.  
  195.     print '<tr><th width=40><br></th><th align=left>Enable tunnel:</th>',
  196.       '<td align=left><strong>';
  197.     print &radio('tun',$val{'tun'},"Yes","No");
  198.     print '</strong></td></tr>';
  199.     print '<tr><th width=40><br></th><th align=left>Interface:</th>',
  200.       '<td align=left>';
  201.     print qq|<select name="int">|;
  202.     for ($i=0;$i<=$#myInt;$i++) {
  203.     if ($locIP ne $myIP[$i]) { print "<option>$myInt[$i] $myIP[$i]"; }
  204.     else { print "<option selected>$myInt[$i] $myIP[$i]"; }
  205.     }
  206.     print "</select>";
  207.     print '</td></tr><tr><th width=40><br></th>',
  208.       '<th align=left>Remote IP address:</th><td align=left>';
  209.     print &text('rip',$val{'rip'},14);
  210.     print '</td></tr>';
  211.     print '</table><br>';
  212.  
  213.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"',
  214.         "onClick=\"do_help('$help_page'); return (false)\"");
  215.  
  216.     print '</form>';
  217. }
  218.  
  219. sub getInfo {
  220.     undef @myInt;
  221.     undef @myIP;
  222.     open(IN, "/usr/OnRamp/bin/htnetwork |");
  223.     while(<IN>) {
  224.     @items = split(/:/);
  225.     if ($items[3]) {
  226.         push(@myInt,$items[1]);
  227.         push(@myIP,$items[3]);
  228.     }
  229.     }
  230.     close(IN);
  231.  
  232.     $val{'rip'} = "";
  233.     $met = 1;
  234.     $val{'tun'} = "No";
  235.  
  236.     $val{'emr'} = &get_config("mrouted");
  237.  
  238.     open(IN,"< $conf");
  239.     while(<IN>) {
  240.     @items = split(/\s+/);
  241.     if ($items[0] ne 'tunnel') { next; }
  242.     for($i=0;$i<=$#myIP;$i++) {
  243.         if ($myIP[$i] eq $items[1]) {
  244.         $val{'rip'} = $items[2];
  245.         $locIP = $myIP[$i];
  246.         $val{'tun'} = "Yes";
  247.         }
  248.     }
  249.     }
  250.     close(IN); 
  251. }
  252.